from functools import lru_cache

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    DEBUG_MODE: bool = True

    STATIC_DIR: str
    STATIC_URL: str
    STATIC_NAME: str

    TEMPLATE_DIR: str
    # 短链接数据库文件名
    SHORT_URL_DB: str = "urls_db.db"
    # 文件上传目录
    UPLOAD_DIR: str = "uploads"

    class Config:
        # env_file = ".env"
        env_file = (".env", ".env.dev")  # .env 配置会覆盖Settings中的同名配置，后面的.env.prod配置会覆盖前面.env的同名配置
        # Settings类中定义常量校验信息，如类型、默认值、不能多于这里定义的常量名
        # .env 配置文件中常量名必须包含于Settings类中同名的变量名，可少不能多，多的会报错


# 缓存Settings实例对象，避免每次调用get_settings()函数都重新实例化Settings对象
@lru_cache()
def get_settings():
    return Settings()


settings = get_settings()
